/********************************************************************************
  * @文件名:
  *     mainwindow.cpp
  * @作者:
  *     xcl
  * @说明:
  *     该文件的主要功能是主窗口的实现文件
  * @注意:
  *     无
  *******************************************************************************/
#include "mainwindow.h"
#include <QApplication>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    pMainTableWidget = new QTabWidget;

    pOcrWidget = new OcrWidget;
    pTransWidget = new TransWidget;
    pCalWidget = new CalculatorWidget;

    pMainTableWidget->addTab(pOcrWidget, QString("OCR"));
    pMainTableWidget->addTab(pTransWidget, QString("翻译"));
    pMainTableWidget->addTab(pCalWidget, QString("计算器"));


    setCentralWidget(pMainTableWidget);
    resize(400, 300);

    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setIcon(QIcon("trayicon.png"));
    trayMenu = new QMenu(this);
    quitAction = new QAction("quit");
    trayMenu->addAction(quitAction);
    trayIcon->setContextMenu(trayMenu);
    trayIcon->show();
    connect(quitAction, &QAction::triggered, qApp, &QApplication::exit);
    connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated);

}

MainWindow::~MainWindow()
{
}

void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
    switch (reason)
    {
    case QSystemTrayIcon::DoubleClick:
        if(!isMaximized())
        {
            showNormal();
        }
        break;
    default:
        break;
    }
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    hide();
    event->ignore();
}
